<?php

namespace plugin\admin\app\controller\plan;


use plugin\admin\app\logic\font\FontLogic;
use plugin\admin\app\logic\plan\RoleLogic;
use support\Request;
use support\Response;
use plugin\admin\app\controller\AuthController;
use support\exception\BusinessException;

class RoleController extends AuthController
{
    
    /**
     * 浏览
     * @return Response
     */
    public function index(): Response
    {
        return view('plan/role/index');
    }

    /**
     * 查询
     * @param Request $request
     * @return Response
     * @throws BusinessException
     */
    public function select(Request $request): Response
    {
        return RoleLogic::getInstance()->select($request);
    }

    /**
     * 插入
     * @param Request $request
     * @return Response
     * @throws BusinessException
     */
    public function insert(Request $request): Response
    {
        if ($request->method() === 'POST') {
            return RoleLogic::getInstance()->insert($request);
        }

        $aiImageCommand = <<<EOD
{
    "prompt": "@prompt",
    "negative_prompt": "",
    "sampler_name": "DPM++ 3M SDE",
    "sampler_index": "DPM++ 3M SDE",
    "seed": -1,
    "steps": 40,
    "clip_skip": 2,
    "batch_size":  "@batch_size",
    "cfg_scale": "7",
    "denoising_strength": 0.7,
    "width": "@wdith",
    "height": "@height",
    "override_settings": {
        "sd_model_checkpoint":"@model",
        "sd_vae": "animevae.pt"
    },
    "tiling": false,
    "alwayson_scripts": {
        "ADetailer": {
            "args": [
                {
                    "ad_model": "face_yolov8n.pt",
                    "ad_prompt": "",
                    "ad_confidence": "0.7",
                    "ad_denoising_strength": "0.7"
                }
            ]
        }
    }
}
EOD;

        return view('plan/role/insert',[
            'ai_image_command'=>$aiImageCommand,
        ]);
    }

    /**
     * 更新
     * @param Request $request
     * @return Response
     * @throws BusinessException
    */
    public function update(Request $request): Response
    {
        if ($request->method() === 'POST') {
            return RoleLogic::getInstance()->update($request);
        }

        $aiImageCommand = <<<EOD
{
    "prompt": "@prompt",
    "negative_prompt": "",
    "sampler_name": "DPM++ 3M SDE",
    "sampler_index": "DPM++ 3M SDE",
    "seed": -1,
    "steps": 40,
    "clip_skip": 2,
    "batch_size":  "@batch_size",
    "cfg_scale": "7",
    "denoising_strength": 0.7,
    "width": "@wdith",
    "height": "@height",
    "override_settings": {
        "sd_model_checkpoint":"@model",
        "sd_vae": "animevae.pt"
    },
    "tiling": false,
    "alwayson_scripts": {
        "ADetailer": {
            "args": [
                {
                    "ad_model": "face_yolov8n.pt",
                    "ad_prompt": "",
                    "ad_confidence": "0.7",
                    "ad_denoising_strength": "0.7"
                }
            ]
        }
    }
}
EOD;
        return view('plan/role/update',[
            'ai_image_command'=>$aiImageCommand,
        ]);
    }

    /**
     * 删除
     * @param Request $request
     * @return Response
     * @throws \support\exception\BusinessException
     */
    public function delete(Request $request): Response
    {
        return RoleLogic::getInstance()->delete($request);
    }

    /**
     * 重新生成
     * @param Request $request
     * @return Response
     * @throws BusinessException
     */
    public function aiRegenerate(Request $request): Response
    {
        return RoleLogic::getInstance()->aiRegenerate($request);
    }

    /**
     * 选择角色特点
     * @param Request $request
     * @return Response
     */
    public function selectTag(Request $request): Response
    {
        return view('plan/role/selecttag');
    }

    /**
     * 角色特点列表
     * @param Request $request
     * @return Response
     */
    public function selectTagList(Request $request): Response
    {
        return RoleLogic::getInstance()->selectTagList($request);
    }
}
